Ext.define('Egitim.controller.KatilimciCtrl', {
	extend: 'Ext.app.Controller',
	views: ['KatilimciForm', 'KatilimciList'],
	stores: ['Katilimci'],
	models: ['Katilimci'],
	projeId: '',
	refs: [{
		ref: 'katilimciForm',
		selector: 'katilimciform'
	},{
		ref: 'katilimciList',
		selector: 'katilimcilist'
	}],
	init: function() {
		this.control({
			'katilimciform button[action=tamam]': {
				click: this.onKaydetKatilimciForm
			},
			'katilimcilist [tip="s"]': {
				specialkey: this.onKatilimciListSearch
			}
		});
	},
	
	onKatilimciListSearch: function (field, e){
		if (e.getKey() == e.ENTER) {
			var form = field.up('form').getForm();
			this.getKatilimciList().getStore().load({
				params: form.getValues()
			});
		}
	},
	
	onKaydetKatilimciForm: function (but) {
		var formPanel = this.getKatilimciForm(),
			form = formPanel.getForm();
		
		if (form.isValid()) {
			if (Ext.isEmpty(form.findField('proje_id').getValue())) {
				if(formPanel.up('tabpanel') && formPanel.up('tabpanel').getProjeId) {
					form.findField('proje_id').setValue(formPanel.up('tabpanel').getProjeId());					
				}
			}
			form.submit({
				success: function(form, action) {
					formPanel.showMessage (1, action.result.msg);
				},
				failure: function(form, action) {
					formPanel.showMessage (0, action.result.msg);
				}
			});
		}	
	}
});